﻿#include <iostream>

using namespace std;

class Solution
{
public:
    // 面试题 01.02. 判定是否互为字符重排
    bool CheckPermutation(string s1, string s2)
    {
        if (s1.size() != s2.size())
            return false;

        int hash[26] = { 0 };
        for (auto ch : s1)
            hash[ch - 'a']++;

        for (auto ch : s2)
        {
            if (hash[ch - 'a'] == 0)
                return false;
            hash[ch - 'a']--;
        }
        return true;
    }
};

int main()
{
    string s1 = "abc";
    string s2 = "cab";
    cout << Solution().CheckPermutation(s1, s2) << endl;

    return 0;
}